package com.jt.aop;

import com.jt.vo.SysResult;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

//接收Controller的异常信息
@RestControllerAdvice //定义全局的异常处理，返回的是JSON
//@ControllerAdvice   返回的是页面
public class AOPException {
    //实现原理 异常通知afterThrowing
    //1.拦截某些异常
    //2.拦截之后如何处理
    @ExceptionHandler({RuntimeException.class, IOException.class})
    //异常处理器，写异常类型
    public SysResult exception(Exception e){
        //打印异常信息
        e.printStackTrace();
        return SysResult.fail();
    }
}
